using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace OpenComposite.EII.Designer.Workflow.Forms
{
	public partial class FormSelectExistingMashupControl : Form
	{
		public FormSelectExistingMashupControl(Repository.Workflow workflow, MashupUIConfigType configType)
		{
			this.DialogResult = DialogResult.Cancel;

			InitializeComponent();

			BindingList<Repository.Workflow.MashupControl> lst = new BindingList<OpenComposite.EII.Repository.Workflow.MashupControl>();
			foreach ( Repository.Workflow.MashupControl mc in workflow.ExtendedProperties.MashupControls.Values ) {
				if ( configType == MashupUIConfigType.Event ) {
					if ( MashupStatics.TypeNamesEvent.Contains(mc.ControlType) ) lst.Add(mc);
				} else {
					if ( MashupStatics.TypeNamesMethod.Contains(mc.ControlType) ) lst.Add(mc);
				}
			}
			dgvControls.AutoGenerateColumns = false;
			dgvControls.DataSource = lst;
		}

		public Repository.Workflow.MashupControl SelectedMashupControl {
			get
			{
				if ( dgvControls.SelectedRows.Count > 0 ) {
					return dgvControls.SelectedRows[0].DataBoundItem as Repository.Workflow.MashupControl;
				} else {
					return null;
				}
			}
		}

		private void tsbtnOK_Click(object sender, EventArgs e)
		{
			if ( dgvControls.SelectedRows.Count == 0 ) {
				MessageBox.Show("Please select an existing control.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);
				return;
			}
			this.DialogResult = DialogResult.OK;
			this.Close();
		}

		private void tsbtnCancel_Click(object sender, EventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;
			this.Close();
		}
	}
}